package com.wuba.rxjavademo.tzx.create;

import com.wuba.rxjavademo.tzx.common.Base;

import rx.Observable;

/**
 * Created by tanzhenxing
 * Date: 2016/6/24.
 * Description:
 * defer:延迟发射
 */
public class RxDefer extends Base {
    public static void main(String[] args) {
        RxDefer defer = new RxDefer();
        defer.init();
        defer.run();
    }

    private void init() {
        Observable<Integer> deferred = Observable.defer(this::getInt);

    }

    @Override
    public void run() {
        Observable<Integer> deferred = getInt();
    }


    private Observable<Integer> getInt() {
        print("getInt");
        return Observable.create(subscriber -> {
                            if (subscriber.isUnsubscribed()) {
                                return;
                            }
                            print("getInt");
                            subscriber.onNext(123);
                            subscriber.onCompleted();
                        });

    }


}
